{% extends 'base.html' %}

    {% block breadcrumb_current %}
        设备管理 > 新增政企接入设备
    {% endblock %}

{% block content %}
    <div class="bg-light p-3 shadow-sm">
        <h5 style="color: #417690;">
            新增政企接入设备
            <a href="{% url 'device_list' %}" class="btn btn-secondary btn-sm float-end">返回设备列表</a></h5>
        </div>
    <div>
<div class ="container mt-4">

    <div class="card-body" style=" margin-top: 30px;">

    {% if messages %}
        <div class="alert alert-danger mb-4">
            <ul class="mb-0">
                {% for message in messages %}
                    <li>{{ message }}</li>
                {% endfor %}
            </ul>
        </div>
    {% endif %}
    
        <form method="post">
            {% csrf_token %}
            <div class="row">
                <div class="col-md-2 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.number.id_for_label }}" class="form-label">设备编号</label>
                    <input type="text" name="{{ form.number.name }}" id="{{ form.number.id_for_label }}" 
                            class="form-control {% if form.number.errors %}is-invalid{% endif %}" 
                            value="{{ form.number.value|default:'' }}" readonly>
                    <small class="text-muted">系统自动生成</small>
                    {% if form.number.errors %}
                        <div class="invalid-feedback">{{ form.number.errors|join:", " }}</div>
                    {% endif %}
                </div>
                <div class="col-md-2 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.factory.id_for_label }}" class="form-label">生产厂家<span class="text-danger">*</span></label>
                    <select name="{{ form.factory.name }}" id="{{ form.factory.id_for_label }}" 
                            class="form-control {% if form.factory.errors %}is-invalid{% endif %}">
                        {% for value, text in form.factory.field.choices %}
                            <option value="{{ value }}" {% if form.factory.value == value %}selected{% endif %}>{{ text }}</option>
                        {% endfor %}
                    </select>
                    {% if form.factory.errors %}
                        <div class="invalid-feedback">{{ form.factory.errors|join:", " }}</div>
                    {% endif %}
                </div>
                <div class="col-md-2 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.technology.id_for_label }}" class="form-label">技术分类<span class="text-danger">*</span></label>
                    <select name="{{ form.technology.name }}" id="{{ form.technology.id_for_label }}" 
                            class="form-control {% if form.technology.errors %}is-invalid{% endif %}">
                        {% for value, text in form.technology.field.choices %}
                            <option value="{{ value }}" {% if form.technology.value == value %}selected{% endif %}>{{ text }}</option>
                        {% endfor %}
                    </select>
                    {% if form.technology.errors %}
                        <div class="invalid-feedback">{{ form.technology.errors|join:", " }}</div>
                    {% endif %}
                </div>
            </div>
            <div class="row">
                <div class="col-md-2 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.place.id_for_label }}" class="form-label">存放位置<span class="text-danger">*</span></label>
                    <select name="{{ form.place.name }}" id="{{ form.place.id_for_label }}" 
                            class="form-control {% if form.place.errors %}is-invalid{% endif %}">
                        {% for value, text in form.place.field.choices %}
                            <option value="{{ value }}" {% if form.place.value == value %}selected{% endif %}>{{ text }}</option>
                        {% endfor %}
                    </select>
                    {% if form.place.errors %}
                        <div class="invalid-feedback">{{ form.place.errors|join:", " }}</div>
                    {% endif %}
                </div>
                <div class="col-md-2 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.state.id_for_label }}" class="form-label">设备状态<span class="text-danger">*</span></label>
                    <select name="{{ form.state.name }}" id="{{ form.state.id_for_label }}" 
                            class="form-control {% if form.state.errors %}is-invalid{% endif %}">
                        {% for value, text in form.state.field.choices %}
                            <option value="{{ value }}" {% if form.state.value == value %}selected{% endif %}>{{ text }}</option>
                        {% endfor %}
                    </select>
                    {% if form.state.errors %}
                        <div class="invalid-feedback">{{ form.state.errors|join:", " }}</div>
                    {% endif %}
                </div>
                <div class="col-md-2 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.model.id_for_label }}" class="form-label">设备型号</label>
                    <input type="text" name="{{ form.model.name }}" id="{{ form.model.id_for_label }}" 
                            class="form-control {% if form.model.errors %}is-invalid{% endif %}" 
                            value="{{ form.model.value|default:'' }}">
                    {% if form.model.errors %}
                        <div class="invalid-feedback">{{ form.model.errors|join:", " }}</div>
                    {% endif %}
                </div>
            </div>
            <div class="row">
                <div class="col-md-2 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.mac.id_for_label }}" class="form-label">MAC地址</label>
                    <input type="text" name="{{ form.mac.name }}" id="{{ form.mac.id_for_label }}" 
                            class="form-control {% if form.mac.errors %}is-invalid{% endif %}" 
                            value="{{ form.mac.value|default:'' }}">
                    {% if form.mac.errors %}
                        <div class="invalid-feedback">{{ form.mac.errors|join:", " }}</div>
                    {% endif %}
                </div>
                <div class="col-md-2 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.summary.id_for_label }}" class="form-label">设备描述</label>
                    <input type="text" name="{{ form.summary.name }}" id="{{ form.summary.id_for_label }}" 
                            class="form-control {% if form.summary.errors %}is-invalid{% endif %}" 
                            value="{{ form.summary.value|default:'' }}">
                    {% if form.summary.errors %}
                        <div class="invalid-feedback">{{ form.summary.errors|join:", " }}</div>
                    {% endif %}
                </div>
                <div class="col-md-2 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.cust_code.id_for_label }}" class="form-label">客户编码</label>
                    <input type="text" name="{{ form.cust_code.name }}" id="{{ form.cust_code.id_for_label }}" 
                            class="form-control {% if form.cust_code.errors %}is-invalid{% endif %}" 
                            value="{{ form.cust_code.value|default:'' }}">
                    {% if form.cust_code.errors %}
                        <div class="invalid-feedback">{{ form.cust_code.errors|join:", " }}</div>
                    {% endif %}
                </div>
            </div>
            <div class="row">
                <div class="col-md-4 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.cust_name.id_for_label }}" class="form-label">客户名称</label>
                    <input type="text" name="{{ form.cust_name.name }}" id="{{ form.cust_name.id_for_label }}" 
                            class="form-control {% if form.cust_name.errors %}is-invalid{% endif %}" 
                            value="{{ form.cust_name.value|default:'' }}">
                    {% if form.cust_name.errors %}
                        <div class="invalid-feedback">{{ form.cust_name.errors|join:", " }}</div>
                    {% endif %}
                </div>
                <div class="col-md-4 mb-3 mx-auto" style="margin-top: 30px;">
                    <label for="{{ form.project.id_for_label }}" class="form-label">所属项目</label>
                    <input type="text" name="{{ form.project.name }}" id="{{ form.project.id_for_label }}" 
                            class="form-control {% if form.project.errors %}is-invalid{% endif %}" 
                            value="{{ form.project.value|default:'' }}">
                    {% if form.project.errors %}
                        <div class="invalid-feedback">{{ form.project.errors|join:", " }}</div>
                    {% endif %}
                </div>
            </div>
            </div>
        <div class="text-center"  style="margin-top: 30px;">
            <button type="submit" class="btn ms-2" style="background-color: #417690; color: white;">保 存</button>
        </div>
        </form>
    </div>
    </div>
</div>
{% endblock %}